Skip to content

refactor(api): extend #206 type-safety to security (#359 batch 8)#384

Merged
brandonrc merged 1 commit intomainfrom
harden/359-type-safety-security
May 9, 2026
Merged

refactor(api): extend #206 type-safety to security (#359 batch 8)#384
brandonrc merged 1 commit intomainfrom
harden/359-type-safety-security

Conversation

@brandonrc
Copy link
Copy Markdown
Contributor

Summary

Closes #359 (partial — batch 8). Same playbook for src/lib/api/security.ts. 25 as never removed; zero retained casts.

13 adapters total (9 read, 4 write) covering the full security graph: Dashboard, Score, Scan, Finding, Policy, ScanConfig, RepoSecurity.

Acceptance criteria

  • No uncommented as unknown as / as never in changed files
  • All tests pass (2085/2085)
  • New code coverage on changed lines: 100% statements / 100% lines / 100% functions / 89% branches

Test plan

  • npm test — 2085/2085
  • npm run lint — 0 errors
  • npm run build — succeeds (TypeScript + Next prerender clean)

Remaining

sso (large, final) — last batch.

🤖 Generated with Claude Code

…tch 8)

Apply the #206 playbook to security.ts. 25 `as never` casts removed.

src/lib/api/security.ts:
  + 9 read adapters: adaptDashboard / adaptScore / adaptScan / adaptScanList /
    adaptFinding / adaptFindingList / adaptPolicy / adaptScanConfig /
    adaptRepoSecurity / adaptTriggerScanResponse — each normalizes SDK's
    `?: T | null` to local type's `: T | null`.
  + 4 write adapters: adaptTriggerRequest / adaptCreatePolicyRequest /
    adaptUpdatePolicyRequest / adaptUpsertConfigRequest — explicit field
    forwarding so a future local-type addition surfaces at typecheck.
  + adaptScore synthesizes total_findings from severity counts (the SDK
    ScoreResponse omits it).
  + assertData on every successful read.

Drift handling:
  - SDK PolicyResponse has fields the local ScanPolicy doesn't model
    (max_artifact_age_days, min_staging_hours, require_signature). Those
    belong to lifecycle policies, not security policies — the SDK conflates
    the two via shared CreatePolicyRequest/UpdatePolicyRequest types
    (same root cause as the SDK type leak in batch 1's lifecycle.ts).
    The adapter intentionally drops them.

Tests rewritten with realistic SDK fixtures (typed as Sdk* for compile-
time drift detection). New regression tests:
  - Score: last_scan_at undefined → null
  - listScans: nullable fields normalization
  - acknowledgeFinding: body shape forwarding
  - getRepoSecurity: null config / null score handling
  - createPolicy / updatePolicy: body shape forwarding

CHANGELOG entry under [Unreleased] / Changed.

Closes #359 (partial — batch 8 of N). Remaining: sso (large, final).
@brandonrc brandonrc requested a review from a team as a code owner May 9, 2026 20:31
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 9, 2026

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@brandonrc brandonrc merged commit 1e7b7c9 into main May 9, 2026
18 checks passed
@brandonrc brandonrc deleted the harden/359-type-safety-security branch May 9, 2026 20:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extend #206 type-safety hardening to remaining lib/api modules

1 participant